# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
        d = ListNode(0, head)
        a = d
        b = a
        c=0
        while a:
            a=a.next
            if c > n:
                b = b.next
            c+=1
        b.next = b.next.next            
        return d.next